package cn.tedu.cqhotel.controller;

import cn.tedu.cqhotel.pojo.dto.StaffManageAddNewDTO;
import cn.tedu.cqhotel.pojo.dto.StaffManageUpdateDTO;
import cn.tedu.cqhotel.pojo.vo.StaffManageListItemVO;
import cn.tedu.cqhotel.pojo.vo.StaffManageStandardVO;
import cn.tedu.cqhotel.service.IStaffManageService;
import cn.tedu.cqhotel.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理员工管理相关请求的控制器
 *
 * @author Wangdongrui
 */
@Slf4j
@RestController
@RequestMapping("/staff-manages")
@Api(tags = "06. 员工管理模块")
@Validated
public class StaffManageController {

    @Autowired
    private IStaffManageService staffManageService;

    public StaffManageController() {
        log.info("创建控制器：StaffManageController");
    }

    @ApiOperation("添加员工管理")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated StaffManageAddNewDTO staffManageAddNewDTO) {
        log.debug("开始处理【添加员工管理】的请求：{}", staffManageAddNewDTO);
        staffManageService.addNew(staffManageAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除员工管理")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "员工管理id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除员工管理】的请求：id={}", id);
        staffManageService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改员工管理信息")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "员工管理id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateById(@PathVariable Long id, StaffManageUpdateDTO staffManageUpdateDTO) {
        log.debug("开始处理【修改员工管理信息】的请求：id={}, staffManageUpdateDTO={}", id, staffManageUpdateDTO);
        staffManageService.updateById(id, staffManageUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("启用员工管理")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "员工管理id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long id) {
        log.debug("开始处理【启用员工管理】的请求：id={}", id);
        staffManageService.setEnable(id);
        return JsonResult.ok();
    }

    @ApiOperation("禁用员工管理")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "员工管理id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long id) {
        log.debug("开始处理【禁用员工管理】的请求：id={}", id);
        staffManageService.setDisable(id);
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询员工管理信息")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "员工管理id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<StaffManageStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询员工管理信息】的请求：id={}", id);
        StaffManageStandardVO staffManage = staffManageService.getStandardById(id);
        return JsonResult.ok(staffManage);
    }

    @ApiOperation("根据name查询员工管理信息")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "name", value = "员工name", required = true, dataType = "string")
    @GetMapping("/name")
    public JsonResult<List<StaffManageListItemVO>> listByName(String name) {
        log.debug("开始处理【根据name查询员工管理信息】的请求：name={}", name);
        List<StaffManageListItemVO> list = staffManageService.listByName(name);
        return JsonResult.ok(list);
    }

    @ApiOperation("根据parentId查询员工管理信息")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "parentId", value = "员工parentId", required = true, dataType = "long")
    @GetMapping("/parentId")
    public JsonResult<List<StaffManageListItemVO>> listByParentId(Long parentId) {
        log.debug("开始处理【根据parentId查询员工管理信息】的请求：parentId={}", parentId);
        List<StaffManageListItemVO> list = staffManageService.listByParentId(parentId);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询员工管理列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult<List<StaffManageListItemVO>> list() {
        log.debug("开始处理【查询员工管理列表】的请求……");
        List<StaffManageListItemVO> list = staffManageService.list();
        return JsonResult.ok(list);
    }

}
